﻿
@{
    ViewBag.Title = "ConsumablesIndex";
   
}
@section Head
{
       @Html.Css("EditForm", "RightSeparateModule", "dp")
       @Html.Js("datepicker")
    <script src="../../Scripts/datepicker-zh.js" type="text/javascript"></script>
       <script type="text/javascript">
           var maiheight = document.documentElement.clientHeight;
           var mainWidth = document.documentElement.clientWidth; // 减去左边的宽度
		   var value_in="";
		   $(document).ready(function () {
		       $("#instockDt").datepicker({ dateFormat: 'yy-mm-dd' });
		       $("#endDt").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
		       var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
		       var gh = maiheight - otherpm - 80;
		       var options = {
		           height: gh,
		           width: mainWidth,
		           url: '@Url.Action("GetDetailList")',
		           colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '入库日期', name: 'InstockDt', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '食材', name: 'Goods_ID', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '数量', name: 'Count', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '操作员', name: 'UserMan', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '备注', name: 'Remark', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 100, sortable: false, hide: true, align: 'left' },
                    { display: '操作人', name: 'OperatorID', width: 80, sortable: false, hide: true, align: 'left' },
                    { display: '订单编号', name: 'OrderNo', width: 80, sortable: false, hide: true, align: 'left' }
			      	],
		           buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItem_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItem_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItem_onclick },
                            { separator: true }
                         ],
		           singleselected: false,
		           title: false,
		           usepager: true,
		           page: 1,
		           rp: 20,
		           rpOptions: [10, 15, 20],
		           showcheckbox: true,
		           rowbinddata: true
		       };
		       $("#SundriesTable_T").flexigrid(options);

		       $("#btnQueryList").bind("click", function () {
		           refreshbyclick();
		       });
		       //新增，删除，修改
		       function toolbarItem_onclick(cmd, grid) {
		           if (cmd == "Add") {
		               OpenModelWindow('@Url.Action("AddConsumablesDetail")',
                        {
                            width: 764,
                            height: 487,
                            caption: "新增零星物品入库",
                            onclose: refresh
                        }
                       );
		           }
		           else if (cmd == 'Edit') {
		               var ids = "";
		               if ($('.trSelected', grid).length == 0 || $('.trSelected', grid).length > 1) {
		                   showLoadingMsg("请选择一行数据进行编辑", { left: 300, top: 2 }, true, 3000);
		                   return false;
		               }
		               else {
		                   var items = $('.trSelected', grid);
		                   for (i = 0; i < items.length; i++) {
		                       if (i == items.length - 1) {
		                           ids += items[i].id.substr(3);
		                       } else {
		                           ids += items[i].id.substr(3) + ", ";
		                       } //if 
		                   } //for
		               }
		               OpenModelWindow('@Url.Action("AddConsumablesDetail")?id=' + ids,
                        {
                            width: 764,
                            height: 484,
                            caption: "维护零星物品入库",
                            onclose: refresh
                        });
		           }
		           else if (cmd == 'Delete') {
		               if ($('.trSelected', grid).length == 0) {
		                   showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
		                   return false;
		               } else {
		                   if (confirm("确定要删除吗?")) {
		                       var rowcount = 0;
		                       var items = $('.trSelected', grid);
		                       for (var i = 0; i < items.length; i++) {
		                           var id = items[i].id.substr(3);
		                           $.ajax({
		                               url: '@Url.Action("Delete")',
		                               type: "POST",
		                               async: false,
		                               data: { id: id },
		                               success: function (data) {
		                                   if (data) {
		                                       rowcount = rowcount + data;
		                                   }
		                               },
		                               error: function () {
		                               }
		                           }); //ajax
		                       } //for
		                       if ($("#orderno").val()) {
		                           refresh();
		                       }
		                       else {
		                           refreshbyclick();
		                       }
		                       showLoadingMsg("共有" + rowcount.toString() + "个零星物品被删除!", { left: 400, top: 6 }, true, 3000);
		                   }
		               }
		           }
		       } // end of toolbarItem_onclick
		       function refreshbyclick() {
		           var idt = ($("#instockDt").val() == null) ? "" : $("#instockDt").val();
		           var iname = ($("#Con_GoodsInfoId").val() == null) ? "" : $("#Con_GoodsInfoId").val();
		           var enddt = ($("#endDt").val() == null) ? "" : $("#endDt").val();
		           if ($("#Con_GoodsInfoGoodsName").val() == "") {
		               iname = "";
		           }
		           options.query = "and ((InstockDt >= '" + idt + "') and (InstockDt <='" + enddt + "')) and "
                                  + "((Goods_ID = '" + iname + "') or ('" + iname + "'=''))";
		           options.newp = 0;
		           $("#SundriesTable_T").flexOptions(options).flexReload();
		       }
		       function refresh() {
		           options.query = "and OrderNo = '" + $("#orderno").val() + "'";
		           options.newp = 0;
		           $("#SundriesTable_T").flexOptions(options).flexReload();
		       }
		   });      
       </script>
}
       <div id="container">
        <div id="mainContent">
            <div id="title" class="title">零星物品列表</div>
            <div id="findDiv">
            @Html.Hidden("orderno")
             <table>
                <tr>
                 <td style="text-align:right; width:80px;">开始日期：</td>
                 <td>@Html.TextBox("instockDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })</td>
                 <td style="text-align:right; width:80px;">结束日期:</td>
                 <td>@Html.TextBox("endDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })</td>
                 <td>&nbsp;&nbsp;&nbsp;零星物品名称:  </td>
                 <td> @Html.Partial("RtnSpoAllGoodsList")
               
                 </td>                     
                 <td><a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>
                 </td>
                </tr>
             </table>
            </div>
            <table id="SundriesTable_T" style="display: none;">
            </table>
        </div>
    </div>
